<?php
namespace modules\iChat\caches;

use caches\BaseCache;

class SocketCache extends BaseCache
{
	const ICHAT_SOCKET_QUEUE = 'iChat_socket_queue';
	const ICHAT_SOCKET_SAVE = 'iChat_socket_save_%s';

	public static $socketQueue = [];
	public static $socketKv    = [];

	public static function lPushSocket($socket)
	{
		//$key = self::gen(self::ICHAT_SOCKET_QUEUE);
		//return self::lpush($key, $socket);
		array_unshift(self::$socketQueue, $socket);
	}
	public static function rPopSocket()
	{
		//$key = self::gen(self::ICHAT_SOCKET_QUEUE);
		//return self::rpop($key);
		return array_pop(self::$socketQueue);
	}
	public static function setSocket($id, $socket)
	{
		//$key = self::gen(self::ICHAT_SOCKET_SAVE, $id);
		//return self::setex($key,1000,$poker);
		self::$socketKv[(string) $id] = $socket;
	}
	public static function getSocket($id)
	{
		//$key = self::gen(self::ICHAT_SOCKET_SAVE, $id);
		//return self::get($key);
		return isset(self::$socketKv[(string) $id]) ?
		 self::$socketKv[(string) $id] : [];
	}
	
}